<template>

  <card-component
    :content-title="contentTitle"
>


    <table-component slot="table"
                     :table-header="tableHeader"
                     :table-data="tableData"></table-component>


  </card-component>

</template>

<script>

  import card from '@/base/card.vue'
  import table from '@/base/AutoWidthTable.vue'

  import request from '@/common/js/request'

  import util from '@/common/js/util'

  export default {
    components: {
      'card-component': card,
      'table-component': table,

    },
    data() {
      return {
        contentTitle: this.$getTextByLangKey("PCBA统计"),
        tableHeader: [],
        tableData: [],
      }
    },
    created: function () {
      console.log('created')
      this.fetchData()

    },
    destroyed: function () {

    },

    watch: {

    },

    methods: {


      fetchData: function () {
        request.requestGetPcbaRecordGetStatistics({},res=>{
          if(res.data.code === 200){
            const data = res.data.data
            this.tableHeader = this.makeHeader(data.headers)
            this.tableData = this.makeList(data.data)
          }
        },res=>{
          this.isRequesting = false
        })

      },

      makeHeader(headers){
        const newHeaders = headers?headers.map(x=>{

          if (x.prop === 'spiPercent') {
            x.type = 'link'
          }
          if (x.prop === 'reflowPercent') {
            x.type = 'link'
          }
          if (x.prop === 'aoiPercent') {
            x.type = 'link'
          }
          x.isShow = true
          return x
        }):[]

        return newHeaders
      },

      makeList(list){
        const newList = list?list.map(x=>{

          const pcbaStatisticsListUrl = `./#/wrapper/pcbaStatisticsTypeList?orderNo=${x.orderNo}&lineName=${x.lineName}&id=${x.id}`

          x.spiPercent_link = `${pcbaStatisticsListUrl}&type=spi&typeTitle=未生产编号`;
          x.reflowPercent_link = `${pcbaStatisticsListUrl}&type=reflow&typeTitle=未过回流焊编号`;
          x.aoiPercent_link = `${pcbaStatisticsListUrl}&type=aoi&typeTitle=AOI未通过编号`;

          return x
        }):[]
        return newList
      },



    },


  }
</script>


<style scoped>
  .el-card {
    box-shadow: 0 0;
    border-radius: 0;
    border: none;
  }
</style>


